﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;

namespace FinMkts.Messaging
{
    [InheritedExport]
    public abstract class Publisher : IDisposable, IService
    {
        public abstract void Start();

        public abstract void Stop();

        public void Dispose()
        {
            try
            {
                Stop();
            }
            catch
            {
                // dispose should never throw an exception
            }
            GC.SuppressFinalize(this);
        }

        public virtual void Publish(AddressedMessage message)
        {
            Publish(new [] { message, });
        }

        public abstract void Publish(IEnumerable<AddressedMessage> messages);       
    }
}